﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace NASA.BeAMartian.Utils
{
    // Some controls, such as the ComboBox, do not bind to enums properly. This helps.
    public class EnumDatum<T>
    {
        static EnumDatum()
        {
            if (typeof(T).IsEnum == false)
                throw new InvalidProgramException("T must be an enum type.");
        }

        public T Value { get; set; }
        public string Name { get; set; }

        public override string ToString()
        {
            return this.Name;
        }

        public override bool Equals(object obj)
        {
            if (obj is T || obj is int || obj is long)
            {
                return this.Value.Equals((T)obj);
            }
            else
            {
                EnumDatum<T> other = obj as EnumDatum<T>;
                if (other != null)
                    return this.Value.Equals(other.Value);
                else
                    return false;
            }
        }

        public override int GetHashCode()
        {
            return this.Value.GetHashCode();
        }
    }
}
